home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / lib-src / b2m.c < prev    next >
C/C++ Source or Header  |  1993-11-16  |  2KB  |  99 lines

  1. /*
  2.  * b2m - a filter for Babyl -> Unix mail files
  3.  *
  4.  * usage:    b2m < babyl > mailbox
  5.  *
  6.  * I find this useful whenever I have to use a
  7.  * system which - shock horror! - doesn't run
  8.  * Gnu emacs. At least now I can read all my
  9.  * Gnumacs Babyl format mail files!
  10.  *
  11.  * it's not much but it's free!
  12.  *
  13.  *   Ed Wilkinson
  14.  *   E.Wilkinson@massey.ac.nz
  15.  *   Mon Nov 7 15:54:06 PDT 1988
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <time.h>
  20. #include <sys/types.h>
  21.  
  22. #include "../src/config.h"
  23.  
  24. #ifdef USG
  25. #include <string.h>
  26. #else
  27. #include <strings.h>
  28. #endif
  29.  
  30. /* BSD's strings.h does not declare the type of strtok.  */
  31. extern char *strtok ();
  32.  
  33. #define TRUE  (1)
  34. #define FALSE (0)
  35.  
  36. int header = FALSE, printing;
  37. time_t ltoday;
  38. char from[256], labels[256], data[256], *p, *today;
  39.  
  40. main (argc, argv)
  41.      int argc;
  42.      char **argv;
  43. {
  44.   ltoday = time(0);
  45.   today = ctime(<oday);
  46.  
  47.   if (gets(data))
  48.     if (strcmp(data, "BABYL OPTIONS:")) {
  49.       fprintf(stderr, "b2m: not a Babyl mailfile!\n");
  50.       exit(-1);
  51.     } else
  52.       printing = FALSE;
  53.   else
  54.     exit(-1);
  55.   if (printing)
  56.     puts(data);
  57.  
  58.   while (gets(data)) {
  59.  
  60. #if 0
  61.     /* What was this for?  Does somebody have something against blank
  62.        lines?  */
  63.     if (!strcmp(data, ""))
  64.       exit(0);
  65. #endif
  66.  
  67.     if (!strcmp(data, "*** EOOH ***") && !printing) {
  68.       printing = header = TRUE;
  69.       printf("From b2m %s", today);
  70.       continue;
  71.     }
  72.     
  73.     if (!strcmp(data, " ")) {
  74.       /* save labels */
  75.       gets(data);
  76.       p = strtok(data, " ,\r\n\t");
  77.       strcpy(labels, "X-Babyl-Labels: ");
  78.  
  79.       while (p = strtok(NULL, " ,\r\n\t")) {
  80.     strcat(labels, p);
  81.     strcat(labels, ", ");
  82.       }
  83.  
  84.       labels[strlen(labels) - 2] = '\0';
  85.       printing = header = FALSE;
  86.       continue;
  87.     }
  88.  
  89.     if (!strlen(data) && header) {
  90.       header = FALSE;
  91.       if (strcmp(labels, "X-Babyl-Labels"))
  92.     puts(labels);
  93.     }
  94.     
  95.     if (printing)
  96.       puts(data);
  97.   }
  98. }
  99.